package cn.ruituo.server;

/**
 * @author oldliu
 * @since 1.0
 */

import cn.ruituo.common.User;

import java.beans.XMLDecoder;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

/***
 * 专门做用户操作的类
 */
public class UserManager {
    //存储位置
    public static final String FILENAME="xml/users.xml";

    private List<User> users=new ArrayList<>();
    {
        try {
            XMLDecoder xd=new XMLDecoder(new FileInputStream(FILENAME));
            users= (List<User>) xd.readObject();
            xd.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //判断是否正确
    //后面的操作脱离xml
    public User login(String u, String p){
        for(User user:users){
            if(user.getName().equals(u)&&user.getPass().equals(p))
                return user;
        }
        return null;
    }
    public boolean regiser(User u){
        return false;
    }
}
